#ifndef GUI_H
#define GUI_H



#include "includes.h"
#include "init.h"
#include "widget_main.h"
#include "widget_replay.h"
#include "widget_buy.h"
#include "widget_setup.h"
#include "widget_play.h"



class main_widget;
class replay_widget;
class setup_widget;
class buy_widget;
class play_widget;

class pre_move_info;
class pre_fire_info;
class pre_buy_info;
class pre_sell_info;



/**	@brief Class containing all graphics used in the game
*
*   \image html gui.jpeg
*/
class g_graphics
{

public:

	//! @brief Constructor loads all graphics
	g_graphics();
	//! @brief Destructor deletes all graphics
	~g_graphics();

	/** @brief	Converts numbers to color name
	*	uses col[] array
	*	@param	x number to convert, constraint: x < "MAX_PL"
	*	@return	color name
	*/
	string get_color( unsigned int x );
	/** @brief	Converts numbers to QColor
	*	uses qcol[] array
	*	@param	x number to convert, constraint: x < "MAX_PL"
	*	@return	pointer to QColor
	*/
	QColor get_QColor( unsigned int x );

	/** @brief Loads resources for unit
	*	@param name name of the unit
	*	@param icons vector of file names for each color and selected/unselected status
	*	@param sound_f filename of the sound for the unit
	*/
	void set_new_units_resources( const string& name, vector< pair< string, string > >& icons, const string& sound_f ); 

	//! path pixmap
	QPixmap* p;

	//! fire line style
	QPen* fire;

	//! map_background
	QBrush* map_background;

	//! array of unit's pixmaps < name < normal, selected > >
	map< string, map< string, pair< QPixmap*, QPixmap* > > > units_pixmaps;
	//! array of terrain pixmaps < number, pixmap >
	map< unsigned int, QPixmap* > terrain_pixmaps;
	//! array of bonus pixmaps < name, pixmap >
	map< string, QPixmap* > bonus_pixmaps;
	//! array of unit's sounds < name, sound >
	map< string, map< string, QSound* > > units_sounds;
	//! array of beginning pixmaps < color, pixmap >
	map< string, QPixmap* > begin_pixmaps;


private:

	//! array for converting number of color to name
	string* col;
	//! array for converting number of color to QColor
	QColor** qcol;

};



/** @brief Main gui window
*
*   \image html gui.jpeg
*/
class gui: public QMainWindow
{

public:

	/**	@brief Constructor creates the window, sets main_widget as the central widget
	*	@param parent Qt parent of the widget
	*	@param flags Qt flags
	*/
	gui( QWidget* parent = 0, Qt::WFlags flags = 0 );


	//! pinter to main_widget
	main_widget* main_w;
	//! pointer ro replay_widget
	replay_widget* replay_w;
	//! pointer to setup_widget
	setup_widget* setup_w;
	//! pointer to buy_widget
	buy_widget* buy_w;
	//! pointer to play_widget
	play_widget* play_w;
	
};



/** @brief Class for controlling the whole gui
*
*   \image html gui.jpeg
*/
class game_gui
{

public:

	/**	@brief	Function for obaining the singleton
	*	@return	pointer to the singleton
	*/
	static game_gui* get_instance();

	//! @brief Deletes gui and graphics
	void rebuild()
	{
	//	if ( g != 0 )
	//		delete g;
	//	if ( graphics != 0 )
	//		delete graphics;
	//	g = 0;
	//	graphics = 0;
	};

	//! @brief Loads all graphics to g_graphics class
	void get_graphics();
	//! @brief Creates gui class
	void create_gui();

	/** @brief Shows network errors when occured
	*	@param s network error message
	*/
	void show_network_error( const string& s );
	/** @brief Shows network connection status on change
	*	@param s network status
	*/
	void show_network_status( const string& s );
	/** @brief Function called at the end of the game
	*	@param won_p winning player, constraint: won_p != 0
	*/
	void show_game_end( player* won_p );

	//! @brief Function called to switch to buy mode
	void start_buy();
	//! @brief Function called to switch to play mode
	void start_game();
	//! @brief Function called to switch to play mode when replaying some game
	void start_replay();
	//! @brief Function called to switch to testing mode
	void start_testing();


	/** @brief Shows sell event in gui
	*	@param u unit to sell
	*	@param psi some aditional information needed for visualising the event
	*/
	void show_sell( unit* u, pre_sell_info* psi );
	/** @brief Shows buy event in gui
	*	@param u u unit to buy
	*	@param x x coordinate where to place the unit, constraint: x < map->size_x
	*	@param y y coordinate where to place the unit, constraint: y < map->size_y
	*	@param pbi some aditional information needed for visualising the event
	*/
	void show_buy( unit* u, unsigned int x, unsigned int y, pre_buy_info* pbi );
	/** @brief Shows move event in gui
	*	@param u moving unit
	*	@param x x coordinate, where it moves, constraint: x < map->size_x
	*	@param y y coordinate, where it moves, constraint: y < map->size_y
	*	@param pmi some aditional information needed for visualising the event
	*/
	void show_move( unit* u, unsigned int x, unsigned int y, pre_move_info* pmi );
	/** @brief Shows fire event in gui
	*	@param u attacking unit
	*	@param x x coordinate, where it attacks, constraint: x < map->size_x
	*	@param y y coordinate, where it attacks, constraint: y < map->size_y
	*	@param pfi some aditional information needed for visualising the event
	*/
	void show_fire( unit* u, unsigned int x, unsigned int y, pre_fire_info* pfi );
	//! @brief Shows next turn event in gui in buy mode
	void show_next_turn_buy();
	//! @brief Shows next turn event in gui
	void show_next_turn();
	//! @brief Forces labels update
	void update_labels();
	
	/** @brief Shows pause event - changes relevant buttons
	*	@param paused true if pause, false if continue
	*/
	void set_paused( bool paused );
	

	//! pointer to gui class
	gui* g;
	//! pointer to g_graphics class
	g_graphics* graphics;


	//! graphics view width
	static const unsigned int VIEW_WIDTH = 30;
	//! graphics view heigth
	static const unsigned int VIEW_HEIGHT = 30;


	int x;


private:

	game_gui( int _x ): x( _x )
	{
		g = 0;
		graphics = 0;
	};
	game_gui( const game_gui& );
	game_gui& operator=( const game_gui& x );
	//! @brief Deletes graphics
	~game_gui()
	{
//		if ( g != 0 )
//			delete g;
		if ( graphics != 0 )
			delete graphics;
	};

};



#endif
